unit Main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ToolWin, Vcl.ComCtrls, Vcl.StdCtrls,
  Vcl.ImgList;

type
  TfmMain = class(TForm)
    mmoSQL: TMemo;
    tlbMain: TToolBar;
    btnOpenFile: TToolButton;
    ilMain: TImageList;
    procedure btnOpenFileClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmMain: TfmMain;

implementation

{$R *.dfm}

procedure TfmMain.btnOpenFileClick(Sender: TObject);
var
  d: TOpenDialog;
  FileName, FileDir: string;
  FileList, TempText, ResultText: TStringList;
  i: integer;
begin
  FileName := '';
  d := TOpenDialog.Create(Self);
  try
    d.InitialDir := ExtractFilePath(Application.ExeName);
    if d.Execute then begin
      FileName := d.FileName;
      FileDir := ExtractFilePath(FileName);
    end;

  finally
    d.Free;
  end;

  if FileName = '' then
    Exit;

  FileList := TStringList.Create;
  try
    TempText := TStringList.Create;
    ResultText := TStringList.Create;
    try
      FileList.LoadFromFile(FileName);
      for i := 0 to FileList.Count-1 do
      begin
        TempText.LoadFromFile(FileDir + FileList[i]);
        ResultText.AddStrings(TempText);
      end;
      FileName := FileDir + StringReplace(DateTimeToStr(Now), ':', '_', [rfReplaceAll]) + '.txt';
      ResultText.SaveToFile(FileName);
    finally
      TempText.Free;
      ResultText.Free;
    end;

  finally
    FileList.Free;
  end;

  mmoSQL.Lines.LoadFromFile(FileName);
end;

end.
